#ifndef __DEVICE_H__
#define __DEVICE_H__

#include "pch.h"
#include "VideoDecoder.h"
#include "VideoEncoder.h"
#include "FpsCalculator.h"
#include <boost/lockfree/spsc_queue.hpp>

class Device
{
public:
    void Init(const std::string &rtsp_url, const std::string &device_id = "", const int32_t gpu_idx = 0, const int32_t cpu_core_idx = -1);

    void Start();

    void Stop();

    void SetOutDir(const std::string &dir);

    void SetGPU(int idx);

    void SetCore(int32_t idx = -1);

    int ReconnectTimes();

    std::string DeviceID();

private:
    void WorkThread();

private:
    std::shared_ptr<VideoDecoder> _video_decoder = nullptr;
    std::shared_ptr<VideoEncoder> _video_encoder = nullptr;

    std::string _rtsp_url = "";
    std::string _device_id = "";

    std::mutex _queue_mtx;

    int32_t _core_idx = -1;
    int32_t _gpu_idx = 0;

    std::shared_ptr<FpsCalculator> _fps_decoder = nullptr;
    std::shared_ptr<FpsCalculator> _fps_process = nullptr;

    std::shared_ptr<std::thread> _work_thread = nullptr;

    // boost::circular_buffer<std::shared_ptr<ImageInfo>> _circular_queue;
    boost::lockfree::spsc_queue<std::shared_ptr<ImageInfo>, boost::lockfree::capacity<5>> _circular_queue;

    bool _start = false;

    std::string _out_dir = "/opt";
};
#endif // __DEVICE_H__